Create Hello, world! Program

In almost every programming tutorial, you get the classic "Hello, World!" For example, and I am to break such a good tradition? Let me tell you how you can say hello to the world with ASP.Net. Double-click Open Solution Explorer by Default.aspx (if it is not already there) already contains a bunch of HTML markup, as well as some content that you can not identify, such as page instructions on top, or form tags Runat attribute on All this will be explained later, but for now, we want to see some working code.

First of all, we will add a Label control to the page. A Label control is some what simple, since it's just used to hold a piece of text. Add the following piece of HTML-looking code somewhere between the set of <form> tags:


<asp:Label runat="server" id="HelloWorldLabel"></asp:Label>

Secondly, add this script block somewhere on the page, preferably below the Page directive in the top:


<%
    HelloWorldLabel.Text = "Hello, world!";
%>

If you have not worked before ASP.Net, then I am sure that you are thinking about things now, but as I said, it is about to see some results right now. To view the page in action, debug -> use debugging without starting, or just press F6. Visual Studio will now compile your project, and launch the page that you are working on in your default browser. The page will contain just one piece of text that says "Hello, world!" Says - Congratulations, you have just created your first ASP.NET website! Here's the full list:


<%
    HelloWorldLabel.Text = "Hello, world!";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label runat="server" id="HelloWorldLabel"></asp:Label>
    </div>
    </form>
</body>
</html>